package com.mycompany.dewcineplanet.repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Repository;

import com.mycompany.dewcineplanet.model.Cliente;


@Repository
public class JdbcClienteRepository {

	
	@Autowired
	private DataSource dataSource;
/*validar Cliente	
	public boolean validarCliente(Long cliente){
		boolean flag = false;
		if(cliente != null){
			if(list != null && list.size() > 0){
				for(int i = 0; i < list.size(); i++){
					if(list.get(i).getCodigo().equals(cliente)){
						flag = true;
						break;
					}
				}
			}
		}
		return flag;
	}*/
/*listado Cliente*/
	private Cliente mapCliente(ResultSet rs) throws SQLException {
		Cliente cliente = null;
		while (rs.next()) {
			if (cliente == null) {
				int id_cliente = rs.getInt("id_cliente");
				String nombre = rs.getString("nombre");
				String apellidoPaterno = rs.getString("apellidoPaterno");
				String apellidoMaterno = rs.getString("apellidoMaterno");
				cliente = new Cliente(id_cliente, nombre,apellidoPaterno,apellidoMaterno);
				cliente.setEntityId(rs.getLong("ID"));
//				account.setEntityId(rs.getLong("ID"));
			}

		}
		if (cliente == null) {
			// no rows returned - throw an empty result exception
			throw new EmptyResultDataAccessException(1);
		}
		return cliente;
	}	
}
